package com.thunder.reader.provider;

import android.net.Uri;
import android.provider.BaseColumns;

/**
 * This class defines columns of FeedProvider also provides
 * some utilities to interact with provider. All client classes
 * should use this class instead of interact with database directly.
 * @author AM
 *
 */
public class Feed {
    private Feed() {}
    
    public static class CommonColumns implements BaseColumns {
        /** The name, or what you want to call this item */
        public static final String TITLE = "title";
        /** The summary, or description about the item */
        public static final String DESCRIPTION = "description";
    }
    
    public static final class Group extends CommonColumns {
        public static final Uri CONTENT_URI = Uri.parse("content://" + FeedProvider.AUTHORITY + "/" + FeedProvider.TABLES[0]);
        public static final String COUNT_UNREAD = "count_unread"; 
        public static final String GROUP_DEFAULT = "Uncategorized";
        public static final String[] PROJECTION = {
            _ID,
            TITLE,
            DESCRIPTION,
            _COUNT,
            COUNT_UNREAD
        };
        // Make sure these indices match items in PROJECTION defined above
        public static final int ID_INDEX = 0;
        public static final int TITLE_INDEX = 1;
        public static final int DESCRIPTION_INDEX = 2;
        public static final int COUNT_INDEX = 3;
        public static final int COUNT_UNREAD_INDEX = 4;
    }
    
    public static final class Source extends CommonColumns {
        
        public static final Uri CONTENT_URI = Uri.parse("content://" + FeedProvider.AUTHORITY + "/" + FeedProvider.TABLES[1]);
        public static final Uri ALL_FEEDS_URI = Uri.parse("content://" + FeedProvider.AUTHORITY + "/all_feeds");
        
        /** Group id, INTEGER, which group this feed falls in */
        public static final String GROUP_ID = "group_id";
        public static final String COUNT_UNREAD = "count_unread"; 
        /** Url, TEXT, which orients to the feed */
        public static final String URL = "url";
        /** Locates the RssFeed xml file */
        public static final String FEED_URL = "feed_url";
        public static final String IMAGE_URL = "image_url";
        /** Last update date, TEXT, when the source is updated last time */
        public static final String MODIFIED_DATE = "modified";
        public static final String IMAGE_ID = "image_id";
        /** 1 is updating, 0 is not updating */
        public static final String UPDATING = "updating";
        public static final String[] PROJECTION = {
            _ID,
            _COUNT,
            COUNT_UNREAD,
            TITLE,
            DESCRIPTION,
            FEED_URL,
            URL,
            IMAGE_URL,
            GROUP_ID,
            IMAGE_ID,
            UPDATING,
        };
        // Make sure these indices match items in PROJECTION defined above
        public static final int ID_INDEX = 0;
        public static final int COUNT_INDEX = 1;
        public static final int COUNT_UNREAD_INDEX = 2;
        public static final int TITLE_INDEX = 3;
        public static final int DESCRIPTION_INDEX = 4;
        public static final int FEED_URL_INDEX = 5;
        public static final int URL_INDEX = 6;
        public static final int IMAGE_URL_INDEX = 7;
        public static final int GROUP_ID_INDEX = 8;
        public static final int IMAGE_ID_INDEX = 9;
        public static final int UPDATING_INDEX = 10;
    }
    
    public static final class Article extends CommonColumns {
        public static final Uri CONTENT_URI = Uri.parse("content://" + FeedProvider.AUTHORITY + "/" + FeedProvider.TABLES[2]);
        
        /** Group id, INTEGER, which group this article falls in */
        public static final String GROUP_ID = "group_id";
        /** Source id, INTEGER, which source this article belongs to */
        public static final String SOURCE_ID = "source_id";
        /** Read, INTEGER, indicating whether this article has been read, 0 read, 1 unread */
        public static final String READ = "read";
        public static final String ARTICLE_URL = "article_url";
        public static final String IMAGE_URL = "image_url";
        /** Content, TEXT, indicating the content of the article in feed */
        public static final String CONTENT = "content";
        /** Favorite, BOOLEAN, whether it is user's favorites */
        public static final String FAVORITE = "favorite";
        /** Publication date, TEXT, when the article is published */
        public static final String PUB_DATE = "pub_date";
        /** The thumbnail id associated in the table image */
        public static final String IMAGE_ID = "image_id";
        
        public static final String[] PROJECTION = {
            _ID,
            TITLE,
            DESCRIPTION,
            ARTICLE_URL,
            IMAGE_URL,
            READ,
            SOURCE_ID,
            GROUP_ID,
            PUB_DATE,
            CONTENT,
            IMAGE_ID,
        };
        // Make sure these indices match items in PROJECTION defined above
        public static final int ID_INDEX = 0;
        public static final int TITLE_INDEX = 1;
        public static final int DESCRIPTION_INDEX = 2;
        public static final int ARTICLE_URL_INDEX = 3;
        public static final int IMAGE_URL_INDEX = 4;
        public static final int READ_INDEX = 5;
        public static final int SOURCE_ID_INDEX = 6;
        public static final int GROUP_ID_INDEX = 7;
        public static final int PUB_DATE_INDEX = 8;
        public static final int CONTENT_INDEX = 9;
        public static final int IMAGE_ID_INDEX = 10;
    }
    
    public static final class Image implements BaseColumns {
        public static final Uri CONTENT_URI = Uri.parse("content://" + FeedProvider.AUTHORITY + "/" + FeedProvider.TABLES[3]);
        
        public static final String _DATA = "_data";
        public static final String[] PROJECTION = {
            _ID,
            _DATA
        };
        // Make sure these indices match items in PROJECTION defined above
        public static final int ID_INDEX = 0;
        public static final int DATA_INDEX = 1;
    }
    
    public static final class WeiboAccount implements BaseColumns {
        public static final Uri CONTENT_URI = Uri.parse("content://" + FeedProvider.AUTHORITY + "/" + FeedProvider.TABLES[4]);
        /** The social data provider, such as Sina weibo, Tencent Weibo */
        public static final String PROVIDER = "provider";
        public static final String USER_ID = "user_id";
        public static final String ACCESS_TOKEN = "access_token";
        public static final String ACCESS_SECRET = "access_secret";
        
        public static final String[] PROJECTION = {
            _ID,
            USER_ID,
            ACCESS_TOKEN,
            ACCESS_SECRET,
        };
        public static final int ID_INDEX = 0;
        public static final int USER_ID_INDEX = 1;
        public static final int ACCESS_TOKEN_INDEX = 2;
        public static final int ACCESS_SECRET_INDEX = 3;
    }
}